﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Model;

namespace University.Workshop.DataAccess
{
    public static class MedicineDataAccess
    {
        static MedicalCenterEntities entities = MedicalCenterEntities.Instance;

        /// <summary>
        /// this method insert a new medicine in the database
        /// </summary>
        /// <param name="medicine">medicine to insert</param>
        public static void RegisterNewMedicine(Medicine medicine)
        {
            if (medicine != null)
            {
                entities.Medicines.Add(medicine);
                entities.SaveChanges();
            }            
        }

        public static ICollection<Medicine> SearchMedicineLow()
        {

            var MedicineLow = from medicine in entities.Medicines
                              where medicine.Quantity < 21 //&& (medicine.BrandName == medicineName || medicine.GenericName == medicineName)
                              select medicine;
            return MedicineLow.ToList();
        }

        public static ICollection<Medicine> SearchExpiredMedicine()
        {
            DateTime dateNow = DateTime.Now.AddDays(20);        
            var ExpiredMedicine = from medicine in entities.Medicines
                                  where medicine.ExpirationDate<dateNow
                                  select medicine;            
            return ExpiredMedicine.ToList();
        }

        public static ICollection<Medicine> ObtainAllMedicines()
        {
            var MedicineLow = from medicine in entities.Medicines
                              select medicine;
            return MedicineLow.ToList();
        }
    }
}
